package com.extension.company.view.home;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

import com.example.library.banner.BannerLayout;
import com.extension.company.admin.R;
import com.extension.company.common.mvp.BaseFragment;
import com.extension.company.contract.home.TwoCategoryContract;
import com.extension.company.presenter.home.TwoCategoryPresenter;
import com.extension.company.view.adapter.TwoCategoryAdapter;
import com.extension.company.view.home.adapter.WebBannerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * create zwk
 * data   2019/2/19
 * 描述：fragmentHome中“涨技能、惠租房...”模块 中的viewpager中的fragment模块
 */
public class TwoCategoryFragment extends BaseFragment<TwoCategoryContract.View, TwoCategoryPresenter>
		implements TwoCategoryContract.View {


	public static TwoCategoryFragment newinstance() {
		return new TwoCategoryFragment();
	}


	private Activity activity;

	@BindView(R.id.mListView)
	ListView mListView;

	private TwoCategoryAdapter adapter;

	@Override
	public TwoCategoryContract.View createView() {
		return this;
	}

	@Override
	public TwoCategoryPresenter createPresenter() {
		return new TwoCategoryPresenter();
	}

	@Override
	public void init() {
		activity = getActivity();
		boolean isFirstFragment = false;  // 通过此判断是否显示banner

		if (getArguments() != null) {
			isFirstFragment = (boolean) getArguments().get("isFirst");
		}

		View headerview = LayoutInflater.from(activity).inflate(R.layout.twocategoryfragment_headerview, null);
		mListView.addHeaderView(headerview);
		adapter = new TwoCategoryAdapter(activity);
		mListView.setAdapter(adapter);

		final BannerLayout banner = headerview.findViewById(R.id.category_fragment_banner);

		List<String> list = new ArrayList<>();
		list.add("http://img0.imgtn.bdimg.com/it/u=1352823040,1166166164&fm=27&gp=0.jpg");
		list.add("http://img3.imgtn.bdimg.com/it/u=2293177440,3125900197&fm=27&gp=0.jpg");
		list.add("http://img3.imgtn.bdimg.com/it/u=3967183915,4078698000&fm=27&gp=0.jpg");
		list.add("http://img0.imgtn.bdimg.com/it/u=3184221534,2238244948&fm=27&gp=0.jpg");
		list.add("http://img4.imgtn.bdimg.com/it/u=1794621527,1964098559&fm=27&gp=0.jpg");
		list.add("http://img4.imgtn.bdimg.com/it/u=1243617734,335916716&fm=27&gp=0.jpg");
		WebBannerAdapter webBannerAdapter = new WebBannerAdapter(getActivity(), list);
		banner.setAdapter(webBannerAdapter);
		webBannerAdapter.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
			@Override
			public void onItemClick(int position) {
				Toast.makeText(getActivity(), "点击了第  " + position + "  项", Toast.LENGTH_SHORT).show();
			}
		});

		if (!isFirstFragment) {
			banner.setVisibility(View.GONE);
		}

	}

	@Override
	public int getMainLayout() {
		return R.layout.base_listview_norefresh;
	}

	@Override
	public void showLoading() {

	}

	@Override
	public void hideLoading() {

	}

	@Override
	public void onError(Throwable throwable) {

	}
}
